package com.example.designpatterns.Iterator;

import java.util.LinkedList;

/**
 * 具体迭代器
 */
public class ConcreteIterator implements Iterator {
    private LinkedList<Object> list;
    private int index = 0;

    public ConcreteIterator(LinkedList<Object> list) {
        this.list = list;
        index = 0;
    }

    @Override
    public Object next() {
        if (this.hasNext())
            return list.get(index++);
        else
            return null;
    }

    @Override
    public boolean hasNext() {
        return index < list.size() && list != null;
    }

    @Override
    public boolean remove() {
        list.remove(index);
        return true;
    }
}
